package com.smz.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smz.dao.TEnterpriseDAO;
import com.smz.entity.PageEntity;
import com.smz.entity.TEnterprise;
import com.smz.service.TEnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TEnterpriseServiceImpl implements TEnterpriseService {

    @Autowired
    private TEnterpriseDAO tEnterpriseDAO;


    @Override
    public PageEntity<TEnterprise> findTEnterprisesPage(Integer current) {
        int count = tEnterpriseDAO.selectTEnterpriseCount();//查询角色的总数
        //显示出来的页数
        int pageCount = count% PageEntity.PAGE_SIZE==0?count/ PageEntity.PAGE_SIZE: PageEntity.PAGE_SIZE+1;
        //调用limit查询进行分页
        List<TEnterprise> tEnterprises= tEnterpriseDAO.selectTEnterpriseByPage((current - 1) * PageEntity.PAGE_SIZE, PageEntity.PAGE_SIZE);
        return new PageEntity<>(tEnterprises,count,current,pageCount);
    }

    @Override
    public List<TEnterprise> findAllTEnterprises() {
        return tEnterpriseDAO.selectAllTEnterprises();
    }

    @Override
    public TEnterprise findTEnterpriseById(Integer id) {
        return tEnterpriseDAO.selectTEnterpriseById(id);
    }

    @Override
    public IPage<TEnterprise> findTEnterpriseByContactsEnterpriseName(Integer start, Integer length, String contacts, String enterpriseName) {
        return tEnterpriseDAO.selectTEnterpriseByContactsEnterpriseName(new Page<TEnterprise>(start,length),contacts,enterpriseName);
    }

    @Override
    public void modifyTEnterpriseById(Integer id, String accountStatus) {
        tEnterpriseDAO.updateTEnterpriseById(id,accountStatus);
    }
}
